#include "bignumbers_mt.h"

#include <bignumbers.h>

#include <QtTest/QTest>

using namespace bignumbers;
using namespace moduletest;

void BigNumbers_mt::toString()
{
    BigInt n1;
    BigInt n2 = BigInt("10");
    BigInt n3 = BigInt("999999999999");
    BigInt n4 = BigInt("-999999999999");

    BigFloat f1 = BigFloat("55.35");
    BigFloat f2 = BigFloat("55");
    BigFloat f3 = BigFloat("-55.35");
    BigFloat f4 = BigFloat("55.1234567");
    BigFloat f5;

    QVERIFY(n1.toString() == "0");
    QVERIFY(n2.toString() == "10");
    QVERIFY(n3.toString() == "999999999999");
    QVERIFY(n4.toString() == "-999999999999");

    QVERIFY(f1.toString() == "55.35");
    QVERIFY(f2.toString() == "55");
    QVERIFY(f3.toString() == "-55.35");
    QVERIFY(f4.toString() == "55.1234567");
    QVERIFY(f5.toString() == "0");
}

void BigNumbers_mt::operatorAssigment()
{
    BigInt n1;

    QVERIFY(n1.toString() == "0");

    BigFloat f1;

    QVERIFY(f1.toString() == "0");

    BigInt n2 = BigInt("999999999999");

    n1 = n2;

    BigFloat f2 = BigFloat("55.1234567");

    f1 = f2;

    QVERIFY(n1.toString() == "999999999999" &&
        n2.toString() == "999999999999");
    QVERIFY(f1.toString() == "55.1234567" &&
        f2.toString() == "55.1234567");
}

void BigNumbers_mt::operatorPlus()
{
    BigInt n1 = BigInt("10");
    BigInt n2 = BigInt("-20");

    BigInt n3 = BigInt("1");
    BigInt n4 = BigInt("999999999999");

    BigInt r1 = n1 + n2;
    BigInt r2 = n3 + n4;

    BigFloat f1 = BigFloat("1.11");
    BigFloat f2 = BigFloat("0.111");

    BigFloat f3 = f1 + f2;

    QVERIFY(r1.toString() == "-10");
    QVERIFY(r2.toString() == "1000000000000");
    QVERIFY(f3.toString(2) == "1.22");
}

void BigNumbers_mt::operatorMinus()
{
    BigInt n1 = BigInt("10");
    BigInt n2 = BigInt("-20");

    BigInt n3 = BigInt("1000000000000");
    BigInt n4 = BigInt("1");

    BigInt r1 = n1 - n2;
    BigInt r2 = n3 - n4;

    BigFloat f1 = BigFloat("1.221");
    BigFloat f2 = BigFloat("0.11");

    BigFloat f3 = f1 - f2;

    QVERIFY(r1.toString() == "30");
    QVERIFY(r2.toString() == "999999999999");
    QVERIFY(f3.toString(2) == "1.11");
}

void BigNumbers_mt::operatorMultiply()
{
    BigInt n1 = BigInt("10");
    BigInt n2 = BigInt("-20");

    BigInt n3 = BigInt("1000000000000");
    BigInt n4 = BigInt("10");

    BigInt r1 = n1 * n2;
    BigInt r2 = n3 * n4;

    BigFloat f1 = BigFloat("1.221");
    BigFloat f2 = BigFloat("2");

    BigFloat f3 = f1 * f2;

    QVERIFY(r1.toString() == "-200");
    QVERIFY(r2.toString() == "10000000000000");
    QVERIFY(f3.toString(2) == "2.44");
}

void BigNumbers_mt::operatorDivide()
{
    BigInt n1 = BigInt("10");
    BigInt n2 = BigInt("-2");

    BigInt n3 = BigInt("10000000000000");
    BigInt n4 = BigInt("10");

    BigInt r1 = n1 / n2;
    BigInt r2 = n3 / n4;

    BigFloat f1 = BigFloat("2.441");
    BigFloat f2 = BigFloat("2");

    BigFloat f3 = f1 / f2;

    QVERIFY(r1.toString() == "-5");
    QVERIFY(r2.toString() == "1000000000000");
    QVERIFY(f3.toString(2) == "1.22");
}
